home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Other / PB_Saver / Source / PasteBoardSaver.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.1 KB  |  94 lines

  1. /* 
  2.  *    Written by Joe Freeman 10/91
  3.  *    This program comes with no warrenty or copyright.
  4.  *    Use at your own risk.  If you don't like it, fix it.
  5.  *    Thats why you have the sources.
  6.  *
  7.  *    V1    27 lines of code
  8.  *    V2    terminate instead of deactivate
  9.  *    V3    hide instead of deactivate
  10.  *
  11.  */
  12.  
  13.  
  14. #import "PasteBoardSaver.h"
  15. #import <libc.h>
  16. #import <appkit/Application.h>        /* NXApp */
  17. #import <appkit/Pasteboard.h>
  18. #import <appkit/SavePanel.h>
  19. #import <appkit/Listener.h>    
  20. #import <defaults.h>    
  21.  
  22. @implementation PasteBoardSaver
  23.  
  24. - appDidInit:sender
  25. {
  26.     [[NXApp appListener] setServicesDelegate:self];
  27.     
  28.     return self;
  29. }
  30.  
  31. #define EPS 1
  32. #define TIFF 2
  33. #define ASCII 3
  34. #define RTF 4
  35.  
  36. - pbToFile:pb
  37.     userData:(const char *)uDat
  38.     error:(char **)aMsg
  39. {
  40.     const NXAtom *types;
  41.     char *data;
  42.     int length;
  43.     int    requested;
  44.     NXStream *memStream;
  45.     id savePanel = [SavePanel new];
  46.  
  47.     requested = atoi(uDat) ;
  48.     types = [pb types];
  49.     while (types && *types){
  50.         if (requested == EPS && *types == NXPostScriptPboardType) {
  51.             [savePanel setRequiredFileType:"eps"];
  52.             break;
  53.     } else if (requested == TIFF  && *types == NXTIFFPboardType){
  54.         [savePanel setRequiredFileType:"tiff"];
  55.         break;
  56.     } else if (requested == ASCII && *types == NXAsciiPboardType){
  57.         [savePanel setRequiredFileType:""];
  58.         break;
  59.     } else  if (requested == RTF && *types == NXRTFPboardType){
  60.         [savePanel setRequiredFileType:"rtf"];
  61.         break;
  62.     }  
  63.     types++;
  64.     }
  65.     
  66.     if (types && *types){
  67.     /* need to get the data out of the pasteboard */
  68.     [pb readType:*types data:&data length:&length];
  69.     
  70.     /* open up save panel, ask for a place to put it and put it there */
  71.     if ([savePanel runModal]){
  72.         memStream = NXOpenMemory(NULL, 0, NX_WRITEONLY);
  73.         NXWrite(memStream, data, length);
  74.         NXSaveToFile(memStream, [savePanel filename]);
  75.         NXCloseMemory(memStream, NX_FREEBUFFER);
  76.         /* everyone hated the fact the old app didn't come back */
  77.     } else {
  78.         //strcpy(*aMsg, "User aborted pasteboard save.");
  79.     }
  80.     }
  81.     if ( NXGetDefaultValue([NXApp appName], "HangAround"))
  82.         [NXApp hide:self];
  83.     else
  84.     [NXApp perform:@selector(terminate:) 
  85.             with:self 
  86.             afterDelay: 1
  87.             cancelPrevious:YES];
  88.     return self;
  89. }
  90.  
  91.  
  92.  
  93. @end
  94.